package com.day06;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class demo01 {
    public static void main(String[] args) {
//        //添加学生信息
//        Student student1 = new Student(1, "jack", 25, '女', 50.4);
//        Student student2 = new Student(2, "smith", 23, '男', 0);
//        Student student3 = new Student(3, "tom", 22, '男', 60.3);
//        Student student4 = new Student(4, "marry", 22, '女', 0);
//        Student student5 = new Student(5, "mila", 24, '女', 38.9);
//        //将学生信息加入到 map中
//        map.put("1", student1);
//        map.put("2", student2);
//        map.put("3", student3);
//        map.put("4", student4);
//        map.put("5", student5);
//        System.out.println("====map中的信息如下====");
//        System.out.println(map);

        //调用菜单,进行修改
        menu();
    }


    static Scanner scanner = new Scanner(System.in);
    //定义一个 HashMap集合
    static Map map = new HashMap();

    //菜单
    public static void menu() {
        while (true) {
            System.out.println("=====菜单=====");
            System.out.println("1. 添加学生");
            System.out.println("2. 删除学生");
            System.out.println("3. 查询学生");
            System.out.println("4. 清除所有");
            System.out.println("5. 退出系统");
            System.out.println("请输入的你选择:");
            //定义一个变量，用于选择菜单
            int key = scanner.nextInt();
            switch (key) {
                case 1:
                    add(); //添加
                    break;
                case 2:
                    remove(); //删除
                    break;
                case 3:
                    update(); //查询
                    break;
                case 4:
                    clear(); //清空
                    break;
                case 5:
                    exit(); //退出
                    return;
            }
        }
    }


    //添加信息
    public static void add() {
        System.out.println("请输入键/编号(数字):");
        int key = scanner.nextInt();
        System.out.println("请输入值（姓名,年龄）:");
        String value = scanner.next();
        map.put(key, value);
    }

    //删除信息
    public static void remove() {
        System.out.println("输入需要删除的键/编号:");
        int key = scanner.nextInt();
        map.remove(key);
        System.out.println("删除成功");
        System.out.println("map中剩余的信息");
        System.out.println(map);
    }

    //查询 map中所有信息
    public static void update() {
        System.out.println("map中的信息如下");
        System.out.println(map);
    }

    //清空
    public static void clear() {
        map.clear();
    }

    //退出
    public static void exit() {
        System.out.println("退出成功...");
    }
}

